<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 准备好容器 -->
    <div id="test">
    </div>
</body>
<!-- 引入依赖 引入的时候，必须就按照这个步骤-->
<script src="../React-js/react.development.js" type = "text/javascript"></script>
<script src = "../React-js/react-dom.development.js" type = "text/javascript"></script>
<script src="../React-js/babel.min.js" type="text/javascript"></script>


<script type="text/babel">
    
    class Login extends React.Component{

        //初始状态
        state = {
            username:'',
            password:''
        }
        saveUsername = (event)=>{
            this.setState({username:event.target.value})
        }

        savePassword = (event)=>{
            this.setState({password:event.target.value})
        }
        
        handleSubmit = (event)=>{
            event.preventDefault()
            const {username,password} = this.state 
            alert(`用户名：${username},密码：${password}`)

        }
        
        render(){
            return(
                <form onSubmit={this.handleSubmit}>
                    用户名：<input onChange={this.saveUsername} type = "text" name = "username"/>    
                    密码：<input onChange={this.savePassword} type = "password" name = "password"/>
                    <button>登录</button>
                </form>
            )
        }
    }
    ReactDOM.render(<Login/>,document.getElementById("test"))
</script>
</html>